﻿Imports System.Runtime.CompilerServices
Imports Microsoft.SharePoint
Imports System.Xml

Namespace Extensions
    Module SPListExtensions
        <Extension()> _
        Public Function Url(ByVal list As SPList) As String
            Dim listUrl As String = list.DefaultViewUrl
            If TypeOf list Is SPDocumentLibrary Then

                Dim index As Integer = listUrl.IndexOf("Forms") + 6
                listUrl = listUrl.Remove(index)

                If listUrl.EndsWith("/") Then
                    listUrl = listUrl.Remove(listUrl.LastIndexOf("/"))
                End If
            Else
                Dim indexSlash As Integer = listUrl.LastIndexOf("/")
                listUrl = listUrl.Remove(indexSlash)
            End If
            Return listUrl
        End Function
    End Module
End Namespace